/**
* Created by wl
* 基金储备库-编辑基金信息
*/
<template>
    <div :class="{'ca-p-20': $route.name.includes('add'), 'ca-m-t-28': $route.name.includes('add'), 'ca-box': $route.name.includes('add')}">
        <div class="ca-title">
            <h3>基金信息</h3>
            <div class="ca-align-right" v-if="$route.params.itemId != '-1' && !$route.name.includes('add')">
                <el-button type="primary" size="small" @click="save()">保存</el-button>
                <el-button size="small" @click="cancel()">取消</el-button>
            </div>
        </div>
        <el-form ref="form1" label-width="150px" :model="fundReserveInfo">
            <el-row :gutter="10">
                <el-col :span='11'>
                    <el-form-item label="投资方向：" label-width="160px">
                        <el-input style="width:100%" v-model="fundReserveInfo.investmentDirection" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="基金来源：" label-width="160px">
                        <el-input style="width:100%" v-model="fundReserveInfo.source" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="组织形式：" label-width="160px">
                        <el-select v-model="fundReserveInfo.organizationalForm" style="width: 100%;">
                            <el-option
                            v-for="item in fundForm"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="办公地址：" label-width="160px"> -->
                        <!-- <csRegion :address='registeredAddress2' :title="'办公地址：'"></csRegion> -->
                    <!-- </el-form-item> -->
                </el-col>
                <el-col :span='11'>
                    <el-form-item label="投资阶段：" label-width="160px">
                        <el-input style="width:100%" v-model="fundReserveInfo.investmentStage" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="管理费(%)：" label-width="160px">
                        <el-input style="width:100%" v-model="fundReserveInfo.expense" :maxlength="100"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="注册地区：" label-width="160px"> -->
                        <!-- <csRegion :address='registeredAddress1' :title="'注册地址：'"></csRegion> -->
                    <!-- </el-form-item> -->
                </el-col>
            </el-row>
            <el-row :gutter="10">
                <el-col :span="22">
                    <csRegion :address='officeAddress' ref="officeAddress" :title="'办公地址：'" :labelWidth="'160px'"></csRegion>
                    <csRegion :address='registeredAddress' ref="registeredAddress" :title="'注册地址：'" :labelWidth="'160px'"></csRegion>
                    <el-form-item label="投资地域：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.region" :maxlength="100"></el-input>
                    </el-form-item>
                    <el-form-item label="收益分配：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.distribution" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="设立背景：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.background" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="行业分析：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.analysis" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="项目遴选：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.projectSelection" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="投资决策：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.decision" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="激励约束：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.excitation" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="跟进投资：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.followOn" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="资产托管：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.trusteeship" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="风险控制：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.risk" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="业绩报酬：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.achievement" :maxlength="4000"></el-input>
                    </el-form-item>
                    <el-form-item label="其他：" label-width="160px">
                        <el-input type="textarea" style="width:100%" v-model="fundReserveInfo.other" :maxlength="4000"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        data() {
            return {
                fundForm: this.$store.state.user.dictionaryMap.fundForm, //组织形式
                registeredAddress: {
                    id: '',
                    businessId: '',
                    province: '',
                    city: '',
                    district: '',
                    businessType: 1,
                    registrationDetailed: ''
                },//注册地址
                officeAddress: {
                    id: '',
                    businessId: '',
                    province: '',
                    city: '',
                    district: '',
                    businessType: 2,
                    registrationDetailed: ''
                }, //办公地址
                fundReserveInfo: {
                    achievement: '', //业绩报酬
                    analysis: '', //行业分析
                    background: '', //设立背景
                    excitation: '', //激励约束
                    decision: '', //投资决策
                    distribution: '', //收益分配
                    expense: '', //管理费(%)
                    followOn: '', //跟进投资
                    fundId: '', //基金id
                    id: '', //主id
                    investmentDirection: '', //投资方向
                    investmentStage: '', // 投资阶段
                    organizationalForm: '', // 组织形式
                    other: '', // 其他
                    projectSelection: '', // 项目遴选
                    region: '', // 投资地域
                    regionList: [],
                    risk: '', // 风险控制
                    source: '', // 基金来源
                    trusteeship: '', // 资产托管
                },
            }
        },
        created() {
        },
        mounted() {
            this.$emit('fundReserveInfo', this.fundReserveInfo);
            if (this.$route.params.itemId && this.$route.params.itemId !== '-1') {
                this.getFundInfo()
            }
        },
        props: {
        },
        watch: {
            // 深度 watcher
            fundReserveInfo: {
                handler: function (fundReserveInfo) {
                    this.$emit('fundReserveInfo', fundReserveInfo);
                },
                deep: true
            },
            registeredAddress: {
                handler: function (registeredAddress) {
                    this.fundReserveInfo.regionList = []
                    this.fundReserveInfo.regionList.push(registeredAddress, this.officeAddress)
                    this.$emit('fundReserveInfo', this.fundReserveInfo);
                },
                deep: true
            },
            officeAddress: {
                handler: function (officeAddress) {
                    this.fundReserveInfo.regionList = []
                    this.fundReserveInfo.regionList.push(this.registeredAddress, officeAddress)
                    this.$emit('fundReserveInfo', this.fundReserveInfo);
                },
                deep: true
            },
        },
        methods: {
            cancel() {
                this.$emit('close')
            },
            getFundInfo() {
                apiHttp(api.CHECK_RESERVEINFO, {fundId: this.$route.params.itemId}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.fundReserveInfo = ret.data;
                        //地区赋值
                        if (this.fundReserveInfo.regionList && this.fundReserveInfo.regionList.length !== 0 ) {
                            this.fundReserveInfo.regionList.map((item)=> {
                                if (item.businessType === 1) { //注册地址
                                    this.registeredAddress = item
                                    //调用子组件的方法----初始化组件
                                    this.$refs.registeredAddress.inview(this.registeredAddress)
                                }
                                if (item.businessType === 2) {//办公地址
                                    this.officeAddress = item
                                    //调用子组件的方法----初始化组件
                                    this.$refs.officeAddress.inview(this.officeAddress)
                                }
                            })
                        }
                    }
                })
            },
            save() {
                this.fundReserveInfo.regionList = []
                //地区处理
                if (this.registeredAddress.province) {
                    this.fundReserveInfo.regionList.push(this.registeredAddress)
                }
                if (this.officeAddress.province) {
                    this.fundReserveInfo.regionList.push(this.officeAddress)
                }
                apiHttp(api.SAVE_RESERVEINFO, this.fundReserveInfo).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.$message({
                            message: '数据保存成功！',
                            type: 'success',
                            center: true
                        });
                        this.$emit('update')
                    }
                })
            },
        },
        components: {
             csRegion: require('__components/region'),//地区
        },
    }
</script>